/*******************************************************************************
 * Copyright (c) 2012 March and Conquest.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package mrusanov.towers.resources;

import mrusanov.towers.localization.Localization;

public class ResourceCost extends ResourceBase {

	private ResourceCost(int bricks, int gems, int beasts) {
		super();
		this.bricks = bricks;
		this.gems = gems;
		this.beasts = beasts;
	}

	public static ResourceCost bricks(int count) {
		return new ResourceCost(count, 0, 0);
	}

	public static ResourceCost gems(int count) {
		return new ResourceCost(0, count, 0);
	}

	public static ResourceCost beasts(int count) {
		return new ResourceCost(0, 0, count);
	}

	public static ResourceCost empty() {
		return new ResourceCost(0, 0, 0);
	}

	public String getLocalizedString() {
		StringBuilder builder = new StringBuilder();
		if (bricks != 0) {
			builder.append(Localization.getString("resource.bricks"));
			builder.append(":");
			builder.append(bricks);
		}

		if (gems != 0) {
			builder.append(Localization.getString("resource.gems"));
			builder.append(":");
			builder.append(gems);
		}

		if (beasts != 0) {
			builder.append(Localization.getString("resource.beasts"));
			builder.append(":");
			builder.append(beasts);
		}

		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + beasts;
		result = prime * result + bricks;
		result = prime * result + gems;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		ResourceCost other = (ResourceCost) obj;
		if (beasts != other.beasts) {
			return false;
		}
		if (bricks != other.bricks) {
			return false;
		}
		if (gems != other.gems) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "ResourceCost [bricks=" + bricks + ", gems=" + gems + ", beasts=" + beasts + "]";
	}
}
